<?php
require_once('version.inc');
require_once('dbaccess.inc');
require_once('language.inc');
require_once('settings.inc');

$unum = $_COOKIE['TPMunum'];
$rstufe = $_COOKIE['TPMrstufe'];
$proto = $_SERVER['HTTPS'];
$location = $_SERVER['REQUEST_URI'];
$host = $_SERVER['HTTP_HOST'];

if ($proto != "on") {	// HTTPS protocol?
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title><? echo "$title_str $strVersion"; ?></title>
	<meta name="Description" content="Project Manager">
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<META name="Author" content="Andreas Theofilu">
	<META name="Publisher" content="Andreas Theofilu = Theos Soft">
	<META name="Copyright" content="Andreas Theofilu">
	<META name="Content-language" content="de">
	<META http-equiv="refresh" content="1; URL=https://<? echo $host . $location; ?>">
</head>
<body>
<center>
<h2><? Output(-1, 218, "Klicken Sie"); ?> <a href="https://<? echo $host . $location; ?>"><? Output(-1, 219, "hier"); ?></a>,
<? Output(-1, 220, "falls die Seite nicht automatisch neu geladen wird."); ?></h2>
</body>
</html>
<?php
   exit;
}

if (isset($unum) || isset($rstufe)) {
   setcookie("TPMunum", "", time() - 3600);
   setcookie("TPMrstufe", "", time() - 3600);
}

require_once('header.inc');

if ($header == 3)
   Journal(401, "index.php: User: $unum");

function FormInitDB() {
?>
<form action="initdb.php" method="post">
   <input type="hidden" name="func" value="FormInitDB">
   <input type="hidden" name="headline" value="2">
   <input type="hidden" name="login" value="1">
<table class="input">
   <tr>
      <th colspan=2 class="sel"><? Output(-1, 221, "Datenbank"); ?></th>
   </tr>
   <tr>
      <td><? Output(-1, 222, "Datenbankname:"); ?></td>
      <td><input type="text" name="dbname" value="pm" size=16 maxlength=16></td>
   </tr>
   <tr>
      <td><? Output(-1, 223, "Domainname:"); ?></td>
      <td><input type="text" name="domain" value="localhost" size=30 maxlength=80></td>
   </tr>
   <tr>
      <th colspan=2 class="sel"><? Output(-1, 91, "Einstellungen f&uuml;r die Planung"); ?></th>
   </tr>
   <tr>
      <td><? Output(-1, 92, "L&auml;nge einer Periode:"); ?></td>
      <td><select name="periode">
             <option value="1"><? Output(-1, 93, "Jahr"); ?></option>
	     <option value="2"><? Output(-1, 94, "Quartal"); ?></option>
	     <option value="3" selected><? Output(-1, 95, "Monat"); ?></option>
	     <option value="4"><? Output(-1, 97, "Tag"); ?></option>
	  </select>
      </td>
   </tr>
   <tr>
      <td><? Output(-1, 98, "Verteilung der Auw&auml;nde:"); ?></td>
      <td><select name="verteil">
             <option value="1"><? Output(-1, 99, "Normalverteilung"); ?></option>
	     <option value="2"><? Output(-1, 100, "Endlastig"); ?></option>
	     <option value="3"><? Output(-1, 101, "Anfangslastig"); ?></option>
	     <option value="4"><? Output(-1, 102, "Anfang&minus; und Endlasig"); ?></option>
	     <option value="5"><? Output(-1, 103, "Mittellastig"); ?></option>
	     <option value="6" selected><? Output(-1, 104, "Individuell"); ?></option>
	  </select>
      </td>
   </tr>
   <tr>
      <td><? Output(-1, 105, "Gr&ouml;&szlig;e einer Arbeitseiheit:"); ?></td>
      <td><select name="einheit">
             <option value="1"><? Output(-1, 106, "Stunde"); ?></option>
	     <option value="2" selected><? Output(-1, 107, "Tag"); ?></option>
	     <option value="3"><? Output(-1, 108, "Woche"); ?></option>
	     <option value="4"><? Output(-1, 109, "Monat"); ?></option>
	     <option value="5"><? Output(-1, 111, "Jahr"); ?></option>
	  </select>
      </td>
   </tr>
   <tr>
      <td><? Output(-1, 112, "L&auml;nge einer Arbeitseinh. in Stunden:"); ?></td>
      <td><input type="text" name="leneinheit" value="8" size=5 maxlength=5>
   </tr>
   <tr>
      <td><? Output(-1, 113, "Projektphasen verwenden?"); ?></td>
      <td><input type="checkbox" name="phase" value="1" checked>
   </tr>
   <tr>
      <td><? Output(-1, 114, "Tasks nach Phasen nummerieren?"); ?></td>
      <td><input type="checkbox" name="numphase" value="1" checked>
   </tr>
   <tr>
      <td><? Output(-1, 115, "Datumsformat:"); ?></td>
      <td><select name="dtformatshort">
             <option value="d.m.Y" <? if ($dtformatshort == "d.m.Y") echo "selected"; ?>>TT.MM.JJJJ</option>
	     <option value="d.m.y" <? if ($dtformatshort == "d.m.y") echo "selected"; ?>>TT.MM.JJ</option>
	     <option value="j.n.Y" <? if ($dtformatshort == "j.n.Y") echo "selected"; ?>>T.M.JJJJ</option>
	     <option value="j.n.y" <? if ($dtformatshort == "j.n.y") echo "selected"; ?>>T.M.JJ</option>
	     <option value="m/d/Y" <? if ($dtformatshort == "m/d/Y") echo "selected"; ?>>MM/DD/YYYY</option>
	     <option value="m/d/y" <? if ($dtformatshort == "m/d/y") echo "selected"; ?>>MM/DD/YY</option>
	     <option value="Y-m-d" <? if ($dtformatshort == "Y-m-d") echo "selected"; ?>>YYYY-MM-DD</option>
	  </select>
      </td>
   </tr>
   <tr>
      <td><? Output(-1, 116, "Periodensicht:"); ?></td>
      <td><input type="checkbox" name="pmlight" value="1" <? if (isset($pmlight) && $pmlight) echo "checked"; ?>></td>
   </td>
   <tr>
      <td><? Output(-1, 117, "Mitarbeiterrolle in Plan:"); ?></td>
      <td><input type="checkbox" name="role" value="1" <? if (isset($role) && $role) echo "checked"; ?>></td>
   </tr>
   <tr>
      <th colspan=2 class="sel"><? Output(-1, 224, "Verwaltungsanwender definieren"); ?></th>
   </tr>
   <tr>
      <td><? Output(-1, 225, "Superuser:"); ?></td>
      <td><input type="text" name="suser" value="root" size=8 maxlength=8></td>
   </tr>
   <tr>
      <td><? Output(-1, 226, "Passwort:"); ?></td>
      <td><input type="password" name="pass1" size=8 maxlength=8></td>
   </tr>
   <tr>
      <td><? Output(-1, 227, "Passwort Vergleich:"); ?></td>
      <td><input type="password" name="pass2" size=8 maxlength=8></td>
   </tr>
</table>
<br>
<input type="submit" value="<? Output(-1, 217, "Weiter -->"); ?>"> <input type="reset">
</form>
<?php
}

# Wir pruefen zunaechst ob es eine Datei gibt, welche die Grunddaten enthaelt,
# die wir zum Betrieb benoetigen. Falls nicht, handelt es sich um den ersten
# Aufruf und wir muessen die Datenbank zunaechst einrichten. Klappt das, sind
# wir im Geschaeft :-).

if (!file_exists("setup/setup.dat")) {
   FormInitDB();
   require('footer.inc');
   exit;
}

if (!file_exists("setup/pmkey.pem") || !file_exists("setup/pmkey.xpem")) {
   require_once('crypt.inc');
   CreateCryptKey();
}

$ini_array = parse_ini_file("setup/setup.dat");
$dbname = $ini_array['dbname'];
$domain = $ini_array['domain'];
$suser = $ini_array['suser'];
$password = $ini_array['password'];
$headline = 1;
$login = 1;

require_once('menu.inc');
?>
<form name="login" action="login.php" method="post" onkeypress="javascript:AktDocument = this">
<input type="hidden" name="headline" value="1">
<table class="input">
   <tr>
      <th class="sel" colspan=2><? Output(-1, 228, "Zugangsdaten"); ?></th>
   </tr>
   <tr>
      <td><? Output(-1, 229, "Benutzername:"); ?></td>
      <td><input type="text" class="inputmust" name="user" size=8 maxlength=8></td>
   </tr>
   <tr>
      <td><? Output(-1, 226, "Passwort:"); ?></td>
      <td><input type="password" class="inputmust" name="pass" size=8 maxlength=8></td>
   </tr>
</table>
<table class="indent"><tr><td>
<?
Button(GetMessage(-1, 230, "Login"), "login");
?>
</td></tr></table>
</form>
<?php

require('footer.inc');
?>
